<?
require '../inc.php';
if(!urs)
{
    g::gowin(surl::get('www')."login.php?ourl=".urlencode(surl::url()));
    exit();   
}
////////////////////
$db_member 	= new db($scfg['db']['member']);
u::times();
//
$my_log  	=  $db_member->row("select * from member_log where urs = ? ",urs);
if(//!$my_log['email_check'] || 
	!$my_log['safe_check']
	|| !$my_log['im_check']
	|| !$my_log['base_check'])
{
	$infoChk  = 0;
}else
{
    $infoChk  = 1;
}
$step = $_GET['step'];
if(empty($step))
{
	tpl::assign("infoChk",$infoChk);
	tpl::display("my/sell.my.tpl.php");
}elseif($step == 'chk')
{
	$my_log  	=  $db_member->row("select * from member_log where urs = ? ",urs);
	if($infoChk)
	{
		g::gowin("?step=cats&cSellType=".$_GET['cSellType']);
	}else
	{
		tpl::display("my/sell.chk.my.tpl.php");
	}
}elseif($step == 'cats')
{
	if(empty($_GET['c1id']) && $_GET['id'])
	{
		$db_goods = &new db($scfg['db']['goods']);
		$arr	  = pct::de($_GET['id']);
		$arr["urs"] = urs;
		$table    = "goods_info";
		$where    = array(
			"where"=>" where urs =:urs and gYmd =:gYmd and gid =:gid ",
			"bind"=>$arr
		);
		$rs 	  = $db_goods->row("select `c1id`,`c2id`,`c3id`,`c4id` from {$table} {$where['where']} ",$where['bind']);
		$cats     = array(
			"c1id" =>$rs["c1id"],
			"c2id" =>$rs["c2id"],
			"c3id" =>$rs["c3id"],
			"c4id" =>$rs["c4id"],
			//"id" =>$_GET["id"],
		);
	}else
	{
	    $cats     = array(
			"c1id" =>$_GET["c1id"],
			"c2id" =>$_GET["c2id"],
			"c3id" =>$_GET["c3id"],
			"c4id" =>$_GET["c4id"],
			//"id"   =>$_GET["id"],
		);
	}
	
	tpl::assign("cSellType",$_GET["cSellType"]);
	tpl::assign("id",$_GET["id"]);
	tpl::assign("cats",$cats);
	tpl::assign("infoChk",$infoChk);	
	tpl::display("my/sell.cats.my.tpl.php");
}elseif($step == 'info')
{
	//默认添加商品
	$Pact     = "addGoodsInfo";
	//connent db
	$db_goods = &new db($scfg['db']['goods']);
	//读原来的信息
	$rs = array();	
	if($_GET['id'])
	{
	    $arr	  = pct::de($_GET['id']);
	    $arr["urs"] = urs;
		$table    = "goods_info";
		$table_desc ="goods_info_desc";
		$where    = array(
			"where"=>" where urs =:urs and gYmd =:gYmd and gid =:gid ",
			"bind"=>$arr
		);
		$rs 	  	= $db_goods->row("select * from {$table} {$where['where']} ",$where['bind']); 
		$rs_desc 	= $db_goods->row("select * from {$table_desc} {$where['where']} ",$where['bind']); 
		$rs["sDesc"]= $rs_desc["sDesc"];
		//echo $db_goods->getsql();
		if($rs)
		{
		    //有ID那就是编缉商品啦
	    	$Pact     = "modifyGoodsInfo";
		}
	};
	$cSellType	  = $_GET['cSellType']
						?$_GET['cSellType']
						:($rs['cSellType']?$rs['cSellType']:1);
	$catIdArr	  = empty($_GET['c1id'])
		    			?array(
							"c1id" =>$rs["c1id"],
							"c2id" =>$rs["c2id"],
							"c3id" =>$rs["c3id"],
							"c4id" =>$rs["c4id"],
						)
						:array(
							"c1id" =>$_GET["c1id"],
							"c2id" =>$_GET["c2id"],
							"c3id" =>$_GET["c3id"],
							"c4id" =>$_GET["c4id"],
						);
	$catNameArr   =cat::id2name($db_goods,$catIdArr);
	tpl::assign('shop_class',shop::subClass($db_goods,$urs));
	tpl::assign('id',$_GET['id']);
	tpl::assign('infoChk',$infoChk);
	tpl::assign('Pact',$Pact);
	tpl::assign('rs',$rs);
	tpl::assign('cSellType',$cSellType);
	tpl::assign('catIdArr',$catIdArr);	
	tpl::assign('catNameArr',$catNameArr);
	tpl::display("my/sell.info.my.tpl.php");
}else if($step == 'ok')
{
	tpl::display("my/sell.ok.my.tpl.php");
}
?>